package TwentyThirdDay;

public class PeakIndexInMountainArray {
    public int peakIndexInMountainArray(int[] arr) {
        int left = 0, right = arr.length - 1;
        int mid = 0;
        while (left < right){
            mid = (left + right) / 2;
            if (mid == left){
                return right;
            }
            if (arr[mid] > arr[mid - 1] && arr[mid] > arr[mid + 1]){
                return mid;
            } else if (arr[mid] > arr[mid - 1] && arr[mid] < arr[mid + 1]) {
                left = mid;
            }else {
                right = mid;
            }
        }
        return mid;
    }
}
